package com.beasts.ant.page.controller;

import com.beasts.ant.page.entity.APGroupPage;
import com.beasts.ant.page.entity.APHomePage;
import com.beasts.ant.page.service.IAPHomePageService;
import com.beasts.ant.page.service.IInitDataService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 入口
 * @author cn_zkn
 * @date 07/05/2018 8:39 AM
 * @since 1.0
 */
@Controller
@RequestMapping("/init")
public class InitDataController {

    @Autowired
    private IInitDataService initDataService;
    @Autowired
    private IAPHomePageService iapHomePageService;

    /**
     * 首页初始化菜单
     * @return
     */
    @RequestMapping({ "/getAllMenu"})
    @ResponseBody
    public List<APGroupPage> getMenu(HttpServletRequest req) {
        String menuId = req.getParameter("menuId");
        return initDataService.findAll();
    }


    /**
     * 条件查询菜单
     * @return
     */
    @RequestMapping({ "/getMenuByPageType"})
    @ResponseBody
    public List<APGroupPage> getMenuByPageType(HttpServletRequest req) {
        return initDataService.findByPageType(req);
    }


    /**
     * mybatis sql测试
     * @return
     */
    @RequestMapping({ "/testMybatis"})
    @ResponseBody
    public List<APHomePage> TestMybatis(HttpServletRequest req) {
//        String order = req.getParameter("order");
//        List<APHomePage>  list = iapHomePageService.queryByPageOrder(order);
        List<APHomePage>  list = iapHomePageService.getHomePage();
        System.out.println(list);
        return list;
    }


    @RequestMapping({ "/testMybatisBySql"})
    @ResponseBody
    public List<APHomePage> TestMybatisBySql(HttpServletRequest req) {
//        String order = req.getParameter("order");
//        List<APHomePage>  list = iapHomePageService.queryByPageOrder(order);
        List<APHomePage>  list = iapHomePageService.getHomePageInfo();
        System.out.println(list);
        return list;
    }

    @RequestMapping("/getByGradeNm2")
    @ResponseBody
    public List<APHomePage> getByGradeNm2(Integer  pageNum,Integer  pageSize){
        //页码数
        pageNum = pageNum == null ? 1 : pageNum;
        //每页显示数
        pageSize = pageSize == null ? 10 : pageSize;
        PageHelper.startPage(pageNum, pageSize);
        List<APHomePage> list =  iapHomePageService.getHomePageInfo();
        Page page = (Page) list;
        List resultList = new ArrayList();
        Map<String, Object> data = new HashMap<>();
        data.put("result",page);
        resultList.add(data);
        return  resultList;
    }
    /**
     * 待办页
     * @return
     */
    @RequestMapping({"/todoWorkList"})
    public String todoWorkList() {
        return "subpage/todoWork/todoWorkList";
    }
    /**
     * 消息页
     * @return
     */
    @RequestMapping({"/messageList"})
    public String messageList() {
        return "subpage/message/messageList";
    }

    /**
     * 消息页
     * @return
     */
    @RequestMapping({"/articleList"})
    public String articleList() {
        return "subpage/article/articleList";
    }

    /**
     * 文章详细
     * @return
     */
    @RequestMapping({"/articleDetail"})
    public String articleDetail(HttpServletRequest req) {
        return "subpage/article/articleDetail";
    }

}
